﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;
using Class_Entity;
using System.Web.Configuration;

namespace DataAccess
{
    public class DALiquidFilling
    {
        SqlConnection con;
        SqlCommand cmd;

        //--------------------------------------------------------------------------------------------

        public bool Add_LiquidFilling(LiquidFilling li)
        {
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spAddLiquidFilling", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                
                cmd.Parameters.AddWithValue("@Name", li.Model);
                cmd.Parameters.AddWithValue("@AirP", li.AirPressure);
                cmd.Parameters.AddWithValue("@AirV", li.AirVolume);
                cmd.Parameters.AddWithValue("@FillingS", li.FillingSpeed);
                cmd.Parameters.AddWithValue("@FillingR", li.FillingRangen);                
                cmd.Parameters.AddWithValue("@Image", li.Image);


                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return true;
        }


        //--------------------------------------------------------------------------------------------

        public bool Edit_LiquidFilling(LiquidFilling li)
        {
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spEditLiquidFilling", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@ID", li.ID);
                cmd.Parameters.AddWithValue("@Name", li.Model);
                cmd.Parameters.AddWithValue("@AirP", li.AirPressure);
                cmd.Parameters.AddWithValue("@AirV", li.AirVolume);
                cmd.Parameters.AddWithValue("@FillingS", li.FillingSpeed);
                cmd.Parameters.AddWithValue("@FillingR", li.FillingRangen);
                cmd.Parameters.AddWithValue("@Image", li.Image);


                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return true;
        }


        //--------------------------------------------------------------------------------------------

        public bool Delete_LiquidFilling(LiquidFilling li)
        {
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spDeleteLiquidFilling", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@ID", li.ID);                
                
                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return true;
        }


        //--------------------------------------------------------------------------------------------

        public DataSet Find_LiquidFilling(LiquidFilling li)
        {
            DataSet ds = new DataSet();
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spFindLiquidFilling", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@ID", li.ID);               
                
                cmd.ExecuteNonQuery();
                data.Fill(ds);
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return ds;
        }

        //--------------------------------------------------------------------------------------------

        public DataSet Load_LiquidFilling(LiquidFilling li)
        {
            DataSet ds = new DataSet();
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spLoadLiquidFilling", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);                


                cmd.ExecuteNonQuery();
                data.Fill(ds);
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return ds;
        }

        //--------------------------------------------------------------------------------------------

        public DataSet Search_LiquidFilling(LiquidFilling li)
        {
            DataSet ds = new DataSet();
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spSearchLiquidFilling", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@name", li.Model);

                cmd.ExecuteNonQuery();
                data.Fill(ds);
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return ds;
        }

        //--------------------------------------------------------------------------------------------

        public DataSet Detail_LiquidFilling(LiquidFilling li)
        {
            DataSet ds = new DataSet();
            try
            {
                con = ConnectionToDataBase.StartConnection();
                con.Open();

                cmd = new SqlCommand("spDetailLiquidFilling", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter data = new SqlDataAdapter(cmd);

                cmd.Parameters.AddWithValue("@ID", li.Model);

                cmd.ExecuteNonQuery();
                data.Fill(ds);
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ConnectionToDataBase.CloseConnection();
            }

            return ds;
        }


    }
}
